/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package lu.med.praxiswahl.wahlumed.service.beans;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Remote;
import javax.ejb.Stateless;

import lu.med.praxiswahl.wahlumed.dao.beans.daointerface.CodeRatesDAOInt;
import lu.med.praxiswahl.wahlumed.model.beans.CodeRatesTBL;
import lu.med.praxiswahl.wahlumed.service.beans.serviceinterface.CodeRateServiceInt;

/**
 * 
 * @author pkendzo
 */

@Stateless
@Remote({ CodeRateServiceInt.class })
public class CodeRateService implements CodeRateServiceInt {

	private CodeRatesTBL tmpCoRa;

	@EJB
	private CodeRatesDAOInt coRaDao;

	public CodeRateService() {
		tmpCoRa = new CodeRatesTBL();
	}

	@Override
	public int createCodeRate(String label, String description, double price_A,
			double price_B) {
		CodeRatesTBL tmpCoRa_1 = new CodeRatesTBL();

		tmpCoRa_1.setLabel(label);
		tmpCoRa_1.setBeschreibung(description);
		tmpCoRa_1.setPreis_A(price_A);
		tmpCoRa_1.setPreis_B(price_B);
		tmpCoRa_1.setPrioritaet(0);

		coRaDao.persist(tmpCoRa_1);
		return RET_OPERATION_DONE_PROPERLY;
	}

	@Override
	public int deleteCodeRate(Long id) {
		coRaDao.delete(id);
		return RET_OPERATION_DONE_PROPERLY;
	}

	@Override
	public void getCodeRate(Long id) {
		tmpCoRa = coRaDao.retrieveCodeRateByID(id);

	}

	@Override
	public String getCodeRateDescription() {
		return tmpCoRa.getBeschreibung();
	}

	@Override
	public String getCodeRateLabel() {
		return tmpCoRa.getLabel();
	}

	@Override
	public double getCodeRatePrice_A() {
		return tmpCoRa.getPreis_A();
	}

	@Override
	public double getCodeRatePrice_B() {
		return tmpCoRa.getPreis_B();
	}

	@Override
	public CodeRatesTBL getCoderRateByID(Long id) {
		return coRaDao.retrieveCodeRateByID(id);
	}

	@Override
	public Long[] getAvailableCodeRatesByID() {
		List<CodeRatesTBL> tmp = coRaDao.findAvailableCodeRates();
		Long[] coRatesIDs = new Long[tmp.size()];

		for (int i = 0; i < tmp.size(); i++) {
			coRatesIDs[i] = tmp.get(i).getId();
		}
		return coRatesIDs;
	}

	@Override
	public void setCodeRateDescription(String description) {
		tmpCoRa.setBeschreibung(description);
		coRaDao.update(tmpCoRa);
	}

	@Override
	public void setCodeRateLabel(String label) {
		tmpCoRa.setLabel(label);
		coRaDao.update(tmpCoRa);
	}

	@Override
	public void setCodeRatePrice_A(double price_A) {
		tmpCoRa.setPreis_A(price_A);
		coRaDao.update(tmpCoRa);

	}

	@Override
	public void setCodeRatePrice_B(double price_B) {
		tmpCoRa.setPreis_B(price_B);
		coRaDao.update(tmpCoRa);

	}

	@Override
	public List<CodeRatesTBL> getAvailableCodeRates() {
		List<CodeRatesTBL> tmpList = coRaDao.findAvailableCodeRates();

		return tmpList;
	}

	@Override
	public int getPrioritaet() {
		return tmpCoRa.getPrioritaet();
	}

	@Override
	public void setPrioritaet(int prioritaet) {
		tmpCoRa.setPrioritaet(prioritaet);
		coRaDao.update(tmpCoRa);

	}

}
